<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div class="container">
        <div class="btns">
            <button>1</button>
            <button>2</button>
            <button>3</button>
        </div>
        <div class="cons">
            <div class="dd">内容1</div>
            <div class="dd">内容2</div>
            <div class="dd">内容3</div>
        </div>
    </div>
</body>

</html>
<script>
    function Table(btns,cons) {
        this.btn = document.querySelectorAll(btns)//btn得类名
        this.con = document.querySelectorAll(cons)//内容的类名
        this.index = 0
        this.bindEvent()
    }
    //绑定事件
    Table.prototype.bindEvent = function () {
        var self = this
        self.changeEvent();
        console.log(self.con);
        
        console.log(this);//指向实例化
        for (var i = 0; i < self.btn.length; i++) {
            self.btn[i].index=i
            self.btn[i].onclick = function () {
                // console.log(this);
                self.index=this.index
                self.changeEvent();
            }
        }


    }
    //切换
    Table.prototype.changeEvent = function () {
        var self = this
        for(var i=0;i<self.con.length;i++){
            console.log(self.con.length);
            
            self.con[i].style.display='none'
            self.con[self.index].style.display='block'
        }
    }
    var res = new Table('.btns button', '.dd')
    console.log(res);

</script>